/*
 * @Author: your name
 * @Date: 2021-09-03 14:59:30
 * @LastEditTime: 2021-09-06 19:00:25
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day10\8-经典继承2.js
 */

function Animal(name, age) {
    this.name = name;
    this.age = age;
    this.sayName = function() {
        console.log(this.name);
    }
}
Animal.prototype.sayAge = function() {
    console.log(this.age);
}

function Dog(name, age, color, type) {
    //经典继承 在子类构造函数借用父类构造函数，要产生关系用call
    //this代指这里的执行环境对象
    Animal.call(this, name, age);
    this.color = color;
    this.type = type;
}
var dog = new Dog('铃铛', 2, 'yellow', '金毛');
console.log(dog);
/*Dog {
    name: '铃铛',
    age: 2,
    sayName: [Function (anonymous)],
    color: 'yellow',
    type: '金毛'
  }*/
dog.sayName(); //铃铛
dog.sayAge(); //error!  因为经典继承只继承了构造函数的方法属性，继承不了构造函数的原型属性方法